package com.cykj.admin.service.impl;

import com.cykj.admin.mapper.VipRuleMapper;
import com.cykj.admin.service.IVipRuleService;
import com.cykj.admin.vo.VipRuleVO;
import com.cykj.common.dto.ResponseDTO;
import com.cykj.common.entity.CompanyCheckDO;
import com.cykj.common.entity.VipDO;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

/**
 * @BelongsProject: smart_recruit_backend
 * @BelongsPackage: com.cykj.admin.service.impl
 * @Author: 小小卢
 * @CreateTime: 2025-08-18 15:25
 * @Description: TODO
 * @Version: 1.0
 */
@Service
public class VipRuleServiceImpl implements IVipRuleService {

    @Autowired
    private VipRuleMapper vipRuleMapper;

    /**
     * @Description: 查询所有vip规则
     * @Param: [vipRuleVO]
     * @return: com.cykj.common.dto.ResponseDTO
     */
    @Override
    public ResponseDTO selectVipRuleList(VipRuleVO vipRuleVO) {
        PageInfo<VipDO> page;
        //开启分页
        PageHelper.startPage(vipRuleVO.getCurrentPage(), vipRuleVO.getPageSize());
        List<VipDO> vipRuleList = vipRuleMapper.selectVipRuleList(vipRuleVO);
        page = new PageInfo<>(vipRuleList);
        if (page.getTotal() < page.getPageSize() && vipRuleList.size() == 0 && page.getTotal() != 0) {
            PageHelper.startPage(vipRuleVO.getCurrentPage(), vipRuleVO.getPageSize());
            vipRuleVO.setCurrentPage(1);
            List<VipDO> companyCheckList2 = vipRuleMapper.selectVipRuleList(vipRuleVO);
            page = new PageInfo<>(companyCheckList2);
        }
        return ResponseDTO.success(page);
    }

    /**
     * @Description: 修改vip规则
     * @Param: [vipRuleVO]
     * @return: com.cykj.common.dto.ResponseDTO
     */
    @Override
    public ResponseDTO updateVipRule(VipRuleVO vipRuleVO) {
        Integer rows = vipRuleMapper.updateVipRule(vipRuleVO);
        if (rows > 0) {
            return ResponseDTO.success(rows);
        }
        return ResponseDTO.error("修改失败");
    }

    /**
     * @Description: 删除vip规则
     * @Param: [vipRuleVO]
     * @return: com.cykj.common.dto.ResponseDTO
     */
    @Override
    public ResponseDTO deleteVipRule(Integer vipId) {
        Integer rows = vipRuleMapper.deleteVipRule(vipId);
        if (rows > 0) {
            return ResponseDTO.success(rows);
        }
        return ResponseDTO.error("删除失败");
    }

    /**
     * @Description: 新增vip规则
     * @Param: [vipRuleVO]
     * @return: com.cykj.common.dto.ResponseDTO
     */
    @Override
    public ResponseDTO addVipRule(VipRuleVO vipRuleVO) {
        Integer rows = vipRuleMapper.addVipRule(vipRuleVO);
        if (rows > 0) {
            return ResponseDTO.success(rows);
        }
        return ResponseDTO.error("新增失败");
    }
}